package com.brsya.movie.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.brsya.base.base.BaseLayoutFragment;
import com.brsya.movie.R;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Brsya
 * CreateDate: 2022/7/6  20:47
 * Description:
 * 多个排行榜
 */
public class RankingFragment extends BaseLayoutFragment {
    public static final int SELECT_FILM = 0;
    public static final int SELECT_TELEPLAY = 1;
    public static final int SELECT_VARIETY = 2;
    public static final int SELECT_COMIC = 3;
    private SlidingTabLayout stlCheckedArea;
    private ViewPager vpRankingBox;


    private String[] tabs = {"电影", "电视剧", "综艺", "动漫"};
    private List<Fragment> fragments;

    public static RankingFragment newInstance(int selectIndex) {

        Bundle args = new Bundle();

        RankingFragment fragment = new RankingFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initView() {
        setContentViewId(R.layout.fragment_ranking);
        stlCheckedArea = findViewById(R.id.stl_checked_area);
        vpRankingBox = findViewById(R.id.vp_ranking_box);
    }

    @Override
    protected void initData() {
        fragments = new ArrayList<>();
        fragments.add(RankingListFragment.newInstance(tabs[SELECT_FILM]));
        fragments.add(RankingListFragment.newInstance(tabs[SELECT_TELEPLAY]));
        fragments.add(RankingListFragment.newInstance(tabs[SELECT_VARIETY]));
        fragments.add(RankingListFragment.newInstance(tabs[SELECT_COMIC]));

        vpRankingBox.setOffscreenPageLimit(4);
        vpRankingBox.setAdapter(new FragmentPagerAdapter(getActivity().getSupportFragmentManager(), FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return tabs[position];
            }

        });


        stlCheckedArea.setViewPager(vpRankingBox);

        vpRankingBox.setCurrentItem(0);
    }
}
